package dragon.verification;

import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Author: Leo
 * @Date: 2020/2/20 13:29
 * 验证码类的代码
 * 如果session要放在redis中，这个类必须要继承serializable
 */
public class VerificationCode implements Serializable {

    private LocalDateTime expiredTime;

    private String code;

    private BufferedImage image;


    public VerificationCode(String code, BufferedImage image, int expiredTime) {
        this.expiredTime = LocalDateTime.now().plusSeconds(expiredTime);
        this.code = code;
        this.image = image;
    }

    public LocalDateTime getExpiredTime() {
        return expiredTime;
    }

    public void setExpiredTime(LocalDateTime expiredTime) {
        this.expiredTime = expiredTime;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public boolean isExpired(){
        LocalDateTime now = LocalDateTime.now();
        return now.isAfter(this.expiredTime);
    }
}
